package com.yuque.controller;

import com.yuque.pojo.user;
import com.yuque.service.UserService;
import com.yuque.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@RestControllerAdvice
public class UserController {
    @ExceptionHandler(Exception.class)
    public Result xx(Exception ex){
        ex.printStackTrace();// 输出异常
        Result pp = new Result();
        pp.setFlag(false);
        pp.setShuju("服务器异常，等会再试");
        return pp;
    }
    @Autowired
    private UserService userService;
    @RequestMapping("/zhuce")
    public Result zhuce(@RequestBody user user){
        int zhuce = userService.zhuce(user);
        return new Result(true,null);
    }
    @RequestMapping("/denglu")
    public Result denglu(@RequestBody user user){
   user denglu = userService.denglu(user);
        if (denglu != null) {
            // 登录成功，但注意：通常不会返回整个User对象
            return new Result(true, denglu);
        } else {
            // 登录失败
            return new Result(false, "用户名或密码错误");
        }
    }
    @RequestMapping("/cha")
    public Result chaxun(@RequestBody user user){
        int chaxun = userService.chaxun(user);
        return new Result(true,chaxun);
    }

}

